//
//  TuijianTableViewCell.m
//  22-AliPlanet_HomeWork
//
//  Created by 曹曹 on 16/8/13.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "TuijianTableViewCell.h"
#import "LittleData.h"
#import "TuijianCollecCell.h"

@interface TuijianTableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation TuijianTableViewCell

- (void)setData:(NSArray<LittleData *> *)data {
    _data = data;
    [_collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _data.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TuijianCollecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"tuijian" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bar"]];
    cell.name.text = _data[indexPath.row].name;
    cell.desc.text = _data[indexPath.row].desc;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat margin = 5;
    CGFloat insect = 10;
    return CGSizeMake((CGRectGetWidth(collectionView.bounds) - margin - insect * 2) / 2, CGRectGetHeight(collectionView.bounds) - margin * 2);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
